package com.focusai.efairy.utils;

import android.text.TextUtils;

import java.math.BigDecimal;
import java.text.DecimalFormat;

/**
 * Created by luo_guangwen on 2017/8/7.
 */

public class DecimalUtils {
    public static String formatNum2(int num) {
        return getDecimalFormater2().format(num);
    }

    public static String formatNum2(long num) {
        return getDecimalFormater2().format(num);
    }

    public static BigDecimal formatScale(BigDecimal num,int scale) {
        num = noNullNumber(num);
        return num.setScale(scale,BigDecimal.ROUND_HALF_EVEN);
    }

    public static String formatNum2(double num) {
        return getDecimalFormater2().format(num);
    }
    /**
     * 保留两位小数
     *
     * @return
     */
    public static DecimalFormat getDecimalFormater2() {
        DecimalFormat df = new DecimalFormat("###,###,###,###,###,###,###,###,###,##0.00");
        return df;
    }
    public static BigDecimal noNullNumber(BigDecimal number) {
        if (number == null) return BigDecimal.ZERO;
        return number;
    }
    public static String formatNum(String num) {
        BigDecimal numb = BigDecimal.ZERO;
        if (!TextUtils.isEmpty(num)){
            numb = new BigDecimal(num);
        }
        DecimalFormat df = new DecimalFormat("00");
        return df.format(numb);
    }


}
